package com.gmail.cpamp21.rnGambler;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BetHNDLR {
	
    public static BetHNDLR bh = new BetHNDLR();
    //betting rooms
    List<Bet> rooms = new ArrayList<Bet>();
    int roomSize = 0;
    
    static rnGambler plugin;
    public BetHNDLR(rnGambler rngambler){
    	plugin = rngambler;
    }
    
    public BetHNDLR(){

    }
    
    public static BetHNDLR getHndlr(){
        return bh;
    }
    
    public Bet getRoom(int i){
        for(Bet a : rooms){
            if(a.getId() == i){
                return a;
            }
        }
        return null;
    }
    
    public void addPlayer(Player p, int i){
        Bet r = getRoom(i);//get the room
        if(r == null){//make sure it is not null
            p.sendMessage("Invalid room!");
            return;
        }

        r.getPlayers().add(p.getName());
    }
    
    public void removePlayer(Player p){
        Bet r = null;
        for(Bet room : rooms){
            if(room.getPlayers().contains(p.getName())){
                r = room;
            }
            
        }
        if(r == null || !r.getPlayers().contains(p.getName())){//make sure it is not null
            p.sendMessage("Invalid operation!");
            return;
        }
        
        r.getPlayers().remove(p.getName());

    }
    
    public Bet createRoom(){
        int num = roomSize + 1;
        roomSize++;

        Bet r = new Bet(num);
        rooms.add(r);

        return r;
    }
    
    public void removeArena(int i) {
        Bet r = getRoom(i);
        if(r == null) {
            return;
        }
        rooms.remove(r);
    }

    public boolean isInGame(Player p){
        for(Bet r : rooms){
            if(r.getPlayers().contains(p.getName()))
                return true;
        }
        return false;
    }
}
